﻿namespace block_explorer.NoiseSystem.Nodes
{
    class Gradient : INode
    {
        double m_x1;
        double m_x2;
        double m_y1;
        double m_y2;
        double m_z1;
        double m_z2;

        double m_x;
        double m_y;
        double m_z;

        double m_vlen;

        public Gradient(double x1, double y1, double z1, double x2, double y2, double z2)
        {
            m_x1 = x1;
            m_x2 = x2;
            m_y1 = y1;
            m_y2 = y2;
            m_z1 = z1;
            m_z2 = z2;

            m_x = x2 - x1;
            m_y = y2 - y1;
            m_z = z2 - z1;

            m_vlen = m_x * m_x + m_y * m_y + m_z * m_z;
        }

        public double Value(double x, double y, double z)
        {
            double dx = x - m_x1;
            double dy = y - m_y1;
            double dz = z - m_z1;
            double dp = dx * m_x + dy * m_y + dz * m_z;
            dp /= m_vlen;
            return dp;
        }
    }
}
